package com.sanpu.kxe.business.main.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.sanpu.kxe.R;
import com.sanpu.kxe.business.main.bean.HomeCenterOutput;
import com.sanpu.kxe.common.interfaces.UrlConstants;
import com.sanpu.kxe.jump.imageloader.JKImageLoader;

import java.util.ArrayList;
import java.util.List;

import butterknife.ButterKnife;

/**
 * Description：首页中间功能栏
 * Created by 薛勇军 on 2019/3/29.
 */

public class HomeCenterAdapter extends BaseAdapter {

    private Context mContext;
    private List<HomeCenterOutput> mOutputs = new ArrayList<>();

    public HomeCenterAdapter(Context mContext) {
        this.mContext = mContext;
    }

    public void setNotifyData(List<HomeCenterOutput> mOutputs) {
        this.mOutputs = mOutputs;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        if (mOutputs == null)
            return 0;
        return mOutputs.size();
    }

    @Override
    public HomeCenterOutput getItem(int position) {
        if (mOutputs == null)
            return null;
        return mOutputs.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = View.inflate(mContext, R.layout.item_home_center, null);
        }
        ImageView icon = ButterKnife.findById(convertView, R.id.icon);
        TextView title = ButterKnife.findById(convertView, R.id.title);

        HomeCenterOutput retDatBean = getItem(position);
        if (retDatBean != null) {
            JKImageLoader.getInstance().displayImage(mContext, UrlConstants.getBaseUrl() + retDatBean.getImage(), icon);
            if (!TextUtils.isEmpty(retDatBean.getTitle())) {
                title.setText(retDatBean.getTitle());
            }
        }
        return convertView;
    }
}
